<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>


<!DOCTYPE html>
<html lang="en">

<body data-type="index" class="theme-white">

<div class="am-g tpl-g">
    <!-- 头部 -->
    <jsp:include page="common/header.jsp"/>
    <!-- 风格切换 -->

    <!-- 侧边导航栏 -->
    <jsp:include page="common/memu.jsp"/>


    <!-- 内容区域 -->
    <div class="tpl-content-wrapper">

        <div class="row-content am-cf">
            <div class="row  am-cf">

                <div class="row">

                    <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                        <div class="widget am-cf">
                            <div class="widget-head am-cf">
                                <div class="widget-title am-fl">存款</div>
                                <div class="widget-function am-fr">
                                    <a href="javascript:;" class="am-icon-cog"></a>
                                </div>
                            </div>
                            <div class="widget-body am-fr">

                                <form class="am-form tpl-form-line-form">
                                    <div class="am-form-group">
                                        <label for="myEmail" class="am-u-sm-3 am-form-label">绑定邮箱 <span class="tpl-form-line-small-title"></span></label>
                                        <div class="am-u-sm-9">
                                            <input type="text" class="tpl-form-input" id="myEmail" placeholder="请输入绑定的邮箱">
                                            <small></small>
                                        </div>
                                    </div>


                                    <div id="bindDiv" class="am-form-group">
                                        <div class="am-u-sm-9 am-u-sm-push-3">
                                            <button onclick="bindEmail();" type="button" class="am-btn am-btn-primary tpl-btn-bg-color-success ">绑定邮箱</button>
                                        </div>
                                    </div>

                                    <div id="unBindDiv" class="am-form-group" style="display: none">
                                        <div class="am-u-sm-9 am-u-sm-push-3">
                                            <button onclick="unBindEmail();" type="button" class="am-btn am-btn-primary tpl-btn-bg-color-success ">解绑邮箱</button>
                                        </div>
                                    </div>

                                </form>
                            </div>
                        </div>
                    </div>
                </div>





            </div>




        </div>



    </div>
</div>
</div>
</div>


<script>

    //页面初始化的方法(页面加载完毕后，执行的方法)
    $(document).ready(function () {
        $('#email').addClass('active')
    });



    function bindEmail() {
        atm.ajax({
            url : '/usreDetail/bindEmail',
            requestMethod : 'POST',
            data : {
                email : $('#myEmail').val()
            },
            success : function (responseData) {
                alert('绑定成功');
            }
        })
    }
</script>

</body>

<script>
    $(document).ready(function () {
        loadMyEmail();
    })

    function loadMyEmail() {
        atm.ajax({
            url : '/userDetail/loadEmail',
            requestMethod : 'POST',
            data : {
            },
            success : function (responseData) {
                let userDetail = responseData.data;
                if (userDetail.status == 2) {
                    $('#unBindDiv').show();
                    $('#bindDiv').hide();
                    $('#myEmail').val(userDetail.email);
                } else {
                    $('#bindDiv').show();
                    $('#unBindDiv').hide();
                }
            }
        })
    }

    function unBindEmail() {
        atm.ajax({
            url : '/userDetail/unBindEmail',
            requestMethod : 'POST',
            data : {
            },
            success : function (responseData) {
               window.location.reload();
            }
        })
    }
</script>

</html>